package Algorithm.math.graphical;

import Common.Utils.UTFactory;
import org.junit.Test;

/**
 * @author 蔚蔚樱
 * @version V1.0
 * @date 2022/10/27 01:57
 * @author-Email micromicrohard@outlook.com
 * @description 计算两点之间的距离
 * @blogURL
 */
public class CalDistanceOfTwoPoint {

    @Test // 验证功能：从数据库获取测试数据，用于单元测试
    public void TestFunc() throws Exception {
        UTFactory.FullTest(this.getClass());
    }

    @Test // 调试功能 : 用于复现错误的测试案例
    public void DoubleTrack() throws Exception {
        String input = "{1.0,2}  ############  {2,4.0}";
        String output = "2.23606797749979";
        UTFactory.DebugTest(this.getClass(), input, output);
    }

    public float calMethod(float[] point1, float[] point2) {
        if (point1 == null || point1.length != 2 ||
                point2 == null || point2.length != 2) {
            return 0;
        }
        /**
         * math grammar Math.pow(a,b): a的b次方
         * math grammar Math.sqrt(c): c的平方根
         * math grammar Math.abs(e): e的绝对值
         */
        float x0 = point1[0];
        float y0 = point1[1];
        float x1 = point2[0];
        float y1 = point2[1];
        double answer = Math.sqrt(Math.pow((x0 - x1), 2) + Math.pow((y0 - y1), 2));
        float d = (float) answer;
        return d;
    }
}
